<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class  User extends NotORM{


    public function getListItems($page,$size){
        $list = $this->getORM()->select('*')->order('age desc')->limit(($page - 1) * $size,$size)->fetchRows();
        return $list;
    }

    public function getListTotal(){
        return  $this->getORM()->count('id');
//        return 10;
    }


    function addAll(){
        $rows = array(
            array('name' => 'A君', 'age'=>12, 'note'=>'AA'),
            array('name' => 'B君', 'age'=>13, 'note'=>'BB'),
            array('name' => 'C君', 'age'=>14, 'note'=>'CC'),
            array('name' => 'D君', 'age'=>15, 'note'=>'DD'),
            array('name' => 'E君', 'age'=>12, 'note'=>'EE'),
            array('name' => 'F君', 'age'=>13, 'note'=>'FF'),
        );
        $rs = $this->getORM()->insert_Multi($rows);
        var_dump($rs);
    }


    function addOne(){
        \PhalApi\DI()->notorm->beginTransaction('db_master');
        $one = [
            'name'=>'小明',
            'age'=>24,
            'note'=>'性格开朗'
        ];
        $rs = \PhalApi\DI()->notorm->user->insert($one);

        \PhalApi\DI()->notorm->commit('db_master');
        echo '插入结果'.$rs;
    }



    function nativeSql(){
        $sql = "select *  from tbl_user where id > :id limit 1";
        $params = [':id'=>10];
        return $this->getORM()->queryAll($sql, $params);
    }


    function addUnique(){
        $unique = ['id'=>11];
        $insert = ['id'=>11, 'name'=>'李宇春','age'=>10];
        $update = ['age'=>2];
        $rs = $this->getORM()->insert_update($unique, $insert, $update);
        return $rs;
    }





}